//
//  EXLoginManager.m
//  Exercise
//
//  Created by 羊谦 on 16/5/31.
//  Copyright © 2016年 NetEase-yangqian. All rights reserved.
//

#import "EXLoginManager.h"
#import "EXUserSettingManager.h"
#import <CommonCrypto/CommonDigest.h>
#include <CommonCrypto/CommonHMAC.h>

@implementation EXLoginManager

+(EXLoginManager *)manager {
    static EXLoginManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[EXLoginManager alloc] init];
    });
    return manager;
}

+(BOOL)isLogin {
    return YES;
    //    return UserSetting.userToken;
}

+(NSString *)base64EncryptionAfterHmacSha1WithValue:(NSString *)value;
{
    NSString *key = @"token";
    
    NSData *keyData = [key dataUsingEncoding:NSUTF8StringEncoding];
    
    NSData *valueData = [value  dataUsingEncoding:NSUTF8StringEncoding];
    
    unsigned char cHMAC[CC_SHA1_DIGEST_LENGTH];
    
    CCHmac(kCCHmacAlgSHA1, keyData.bytes, keyData.length, valueData.bytes, valueData.length, cHMAC);
    
    NSData *HMACData = [NSData dataWithBytes:cHMAC length:sizeof(cHMAC)];
    
    NSString *base64Str = [HMACData base64EncodedStringWithOptions:0];
    
    return base64Str;
}

@end
